using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Marlimer.Common;
using Marlimer.Common.Entidades;

namespace Marlimer.Data.Comercial
{
    public class com_Supervisor
    {
        public DataTable getDTSupervisor()
        {
            SqlCommand sqlcmd = new SqlCommand();
            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();
            sqlcmd.CommandText = "spsdtSupervisor";
            sqlcmd.CommandType = CommandType.StoredProcedure;
            sqlcmd.Connection = Session.getConexion();

            da.SelectCommand = sqlcmd;
            da.Fill(ds);

            return ds.Tables[0];
        }

        public DataTable consultaSupervisor(int ccod_super, String cape_pat, String cape_mat, String cnombres, int ctip_docide, String cnum_docide, int flg_anulados)
        {
            SqlCommand sqlcmd = new SqlCommand();
            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();
            sqlcmd.CommandText = "spsConsultaSupervisor";
            sqlcmd.CommandType = CommandType.StoredProcedure;
            sqlcmd.Connection = Session.getConexion();

            sqlcmd.Parameters.Add("@ccod_super", SqlDbType.Int);
            sqlcmd.Parameters.Add("@cape_pat", SqlDbType.NVarChar, 25);
            sqlcmd.Parameters.Add("@cape_mat", SqlDbType.NVarChar, 25);
            sqlcmd.Parameters.Add("@cnombres", SqlDbType.NVarChar, 30);
            sqlcmd.Parameters.Add("@ctip_docide", SqlDbType.Int);
            sqlcmd.Parameters.Add("@cnum_docide", SqlDbType.NVarChar, 11);
            sqlcmd.Parameters.Add("@flg_anulados", SqlDbType.Int);

            sqlcmd.Parameters["@ccod_super"].Value = ccod_super;
            sqlcmd.Parameters["@cape_pat"].Value = cape_pat;
            sqlcmd.Parameters["@cape_mat"].Value = cape_mat;
            sqlcmd.Parameters["@cnombres"].Value = cnombres;
            sqlcmd.Parameters["@ctip_docide"].Value = ctip_docide;
            sqlcmd.Parameters["@cnum_docide"].Value = cnum_docide;
            sqlcmd.Parameters["@flg_anulados"].Value = flg_anulados;

            da.SelectCommand = sqlcmd;
            da.Fill(ds);

            return ds.Tables[0];
        }

        public resulMsgError guardar(InfoSupervisor super)
        {
            resulMsgError resul = new resulMsgError(false, "");

            SqlCommand sqlcmd = new SqlCommand();
            sqlcmd.CommandText = "spiaSupervisor";
            sqlcmd.CommandType = CommandType.StoredProcedure;
            sqlcmd.Connection = Session.getConexion();

            sqlcmd.Parameters.Add("@ccod_super", SqlDbType.Int);
            sqlcmd.Parameters.Add("@cape_pat", SqlDbType.NVarChar, 25);
            sqlcmd.Parameters.Add("@cape_mat", SqlDbType.NVarChar, 25);
            sqlcmd.Parameters.Add("@cnombres", SqlDbType.NVarChar, 30);
            sqlcmd.Parameters.Add("@ctip_docide", SqlDbType.Int);
            sqlcmd.Parameters.Add("@cnum_docide", SqlDbType.NVarChar, 11);
            sqlcmd.Parameters.Add("@cstatus", SqlDbType.NChar, 1);
            sqlcmd.Parameters.Add("@cpc_crea", SqlDbType.NVarChar, 50);
            sqlcmd.Parameters.Add("@cuser_crea", SqlDbType.Int);
            sqlcmd.Parameters.Add("@cmodo", SqlDbType.Int);

            sqlcmd.Parameters["@ccod_super"].Value = super.ccod_super;
            sqlcmd.Parameters["@cape_pat"].Value = super.cape_pat;
            sqlcmd.Parameters["@cape_mat"].Value = super.cape_mat;
            sqlcmd.Parameters["@cnombres"].Value = super.cnombres;
            sqlcmd.Parameters["@ctip_docide"].Value = super.ctip_docide;
            sqlcmd.Parameters["@cnum_docide"].Value = super.cnum_docide;
            sqlcmd.Parameters["@cstatus"].Value = super.cstatus;
            sqlcmd.Parameters["@cpc_crea"].Value = Session.getComputerName();
            sqlcmd.Parameters["@cuser_crea"].Value = Session.getInfousuario().ccod_user;
            sqlcmd.Parameters["@cmodo"].Value = super.cmodo;

            try
            {
                sqlcmd.ExecuteNonQuery();
                //verificamos el tipo de mensaje a mostrar
                if (super.cmodo == 3)
                {
                    resul.message = "Anulado satisfactoriamente";
                }
                else
                {
                    resul.message = "Se guardo satisfactoriamente";
                }
                resul.resul = true;
            }
            catch (Exception ex)
            {
                resul.message = ex.Message;
            }
            return resul;
        }

    }
}
